﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TienTeTuong.back_end
{
    public partial class EditCategory : System.Web.UI.Page
    {
        public CategoryDTO item = new CategoryDTO();
        public CategoryBUS cateBus = new CategoryBUS();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Admin"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            if (Page.IsPostBack)
            {
                string id = Request.Params["id"] ?? "";
                item = cateBus.GetCateByID(id);
                item.CateName = txtName.Text;
                item.Description = txtDescription.Text;
                item.Active = bool.Parse(isActive.Value);
                if (Session["img"] != null)
                {
                    item.Image = Session["img"].ToString();
                    Session["img"] = null;
                }
                item.Price = 0;
                cateBus.update(item);
                Response.Redirect("categorymanagement.aspx");
            }
            else
            {
                string id = Request.Params["id"] ?? "";
                item = cateBus.GetCateByID(id);
                Session["img"] = null;
                txtName.Text = item.CateName;
                txtDescription.Text = item.Description;
                isActive.Value = item.Active.ToString();
            }
        }
    }
}